﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Globalization;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Http.Filters;
using log4net;
using log4net.Config;
using System.Web.Routing;

namespace MvcFilters.Filters
{

    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
    sealed class LogErrorsAttribute : System.Web.Mvc.HandleErrorAttribute
    {

        private ILog logger;

        public LogErrorsAttribute()
        {
            XmlConfigurator.Configure();
            this.logger = LogManager.GetLogger(typeof(LogErrorsAttribute));
        }

        public override void OnException(ExceptionContext filterContext)
        {
            String MensajeDeExcepcion = filterContext.Exception.Message;
            String Metodo = filterContext.Exception.TargetSite.Name;
            String Tipo = filterContext.Exception.TargetSite.DeclaringType.FullName;
            String mensaje = "Surgió una excepción en el método [" + Metodo + "] de [" + Tipo + "] con el siguiente mensaje: [" + MensajeDeExcepcion + "]";
            this.logger.Debug(mensaje);
        }


    }


}